<template>
  <div class="flex flex-col h-full">
    <searchContainer @search="getData" @reset="() => formRef.resetFields()">
      <a-form ref="formRef" class="form-style-flex" :model="formState" :colon="false">
        <a-form-item name="mcbm" class="w-64">
          <a-input v-model:value="formState.mcbm" placeholder="员工编号/员工姓名/助记码" />
        </a-form-item>
        <a-form-item label="科室" name="ks" class="ml-5">
          <SelectSection v-model:value="formState.ks" class="!w-64" trigger="focus" />
        </a-form-item>
      </a-form>
    </searchContainer>
    <a-card class="mt-2 flex-1">
      <baseTable :loading="loading" column-code="000246" fill :pagination="pagination" :data-source="tableData" bordered>
        <template #bodyCell="{ column, index, record }">
          <template v-if="column.dataIndex === 'xh'">
            {{ index + 1 }}
          </template>
          <template v-if="column.dataIndex === 'visitInterval'">
            <EditCell title="就诊间隔">
              <a-input v-model:value="record.visitInterval" v-input:int suffix="分钟" placeholder="请输入" @blur="onBlur(record)" />
            </EditCell>
          </template>
          <template v-if="column.dataIndex === 'quantityLimit'">
            <EditCell title="限号">
              <a-input v-model:value="record.quantityLimit" v-input:int suffix="人次" placeholder="请输入" @blur="onBlur(record)" />
            </EditCell>
          </template>
          <template v-if="column.dataIndex === 'memo'">
            <EditCell title="备注">
              <a-input v-model:value="record.memo" placeholder="请输入" @blur="onBlur(record)" />
            </EditCell>
          </template>
        </template>
      </baseTable>
    </a-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { message } from 'ant-design-vue'
import { post } from '@/utils/request'
import searchContainer from '@/components/SearchContainer'
import baseTable from '@/components/BaseTable'

const formRef = ref(null)
const formState = ref({})

const { loading, getData, tableData, pagination } = useTable({
  url: '/operation/scheduling/getEmpInfoList',
  params: formState.value,
  immediate: true
})

const onBlur = async (row) => {
  const { code, msg } = await post('/operation/scheduling/saveEmpInfo', row)
  if (code !== 0) return message.error(msg)
  message.success(msg)
  getData()
}
</script>
<style lang="less" scoped>
.ant-picker {
  width: 100%;
}
</style>
